limsLocationBoard.editKshPage = {

    getGridParam: function () {
        var _this = this;
        return {
            type: 'grid',
            id: 'lims-location-board-edit-list-grid',
            url: limsLocationBoard.baseUrl + '/queries/raw',
            service: 'limsLocationBoardServiceImpl',
            dbTable: 'T_LIMS_LOCATION_BOARD',
            columns: limsLocationBoard.getEditListColumns(),
            onLoadSuccess: function (rows) {
                if (!Gikam.isEmpty(rows)) {
                    this.activeRowByIndex(0);
                } else {
                    // Gikam.cleanCompData(['sample-Location']);
                }
            },
            onRowActive: function (index, row) {
                // _this.loadHoleList(row.id);
            },
            filterOpen: true,
            toolbar: [{
                type: 'button',
                text: 'GIKAM.BUTTON.INSERT',
                icon: 'add',
                onClick: function () {
                    Gikam.preInsert({
                        modalTitle: 'GIKAM.BUTTON.INSERT',
                        fields: limsLocationBoard.getBaseInfoFormFields(),
                        url: limsLocationBoard.baseUrl
                    }).done(function (id) {
                        Gikam.getComp('lims-location-board-edit-list-grid').refresh();
                        limsLocationBoard.loadKSHBoardHoleDetailPage({id:id})
                    });
                }
            }, {
                type: 'button',
                text: 'GIKAM.BUTTON.DELETE',
                icon: 'remove-row',
                onClick: function () {
                    Gikam.getComp('lims-location-board-edit-list-grid').deleteRows(limsLocationBoard.baseUrl);
                }
            }],
            deleteFormatter: function (row) {
                return row.boardCode;
            },
            page: true,
            requestData: {
                createdByOrgId_EQ: workspace.user.ext$.loginorgid,
            },
            onCellClick: function (field, row) {
                field === 'boardCode' && limsLocationBoard.loadKSHBoardHoleDetailPage(row)
            },
        }
    },

    loadHoleList : function(id){
        Gikam.postSync(limsLocationBoard.holeUrl + '/queries', Gikam.getJsonWrapper({
            f: {
                boardId_EQ: id
            },
            o: [{
                y : 'asc'
            },{
                x : 'asc'
            }],
            n: -1, s: -1
        })).done(function (data) {
            const  iframDom=document.querySelector("#ksh-location-board-iframe >iframe");
            var flag=false;  //是否初次加载

            iframDom.onload=function(){
                flag =true;
                iframDom.contentWindow.postMessage(data.rows, "*");
            };
            if(!flag){
                iframDom.contentWindow.postMessage(data.rows, "*");
            }
        });
    },

    getBaseInfoTab: function () {
        var _this = this;
        return {
            type: 'tab',
            panels: [{
                title: 'BASELINE.SAMPLEMANAGE.LOCATIONS.TAB.BASE_INFO',
                items: [{
                    type: 'form',
                    service: 'limsLocationBoardServiceImpl',
                    dbTable: 'T_LIMS_LOCATION_BOARD',
                    id: 'lims-location-board-edit-list-base-info-form',
                    fields: limsLocationBoard.getBaseInfoFormFields(),
                    onUpdated: function () {
                        var grid = Gikam.getComp('lims-location-board-edit-list-grid');
                        grid.refreshRowById(grid.getActivedRow().id);
                    },
                }]
            }]
        }
    },

    loadBatchDetailPage: function (id) {
        var _this = this;
        Gikam.create('modal', {
            height: '90%',
            width: '90%',
            title: 'BASELINE.BUSINESS.BATCH.MODAL.DETAIL',
            url: IFM_CONTEXT + '/secure/baseline/business/batchs/page/detail-top' + Gikam.param({
                id: id
            }),
        })
    },

    create: function () {
        var _this = this;
        Gikam.create('layout', {
            id: 'lims-location-board-edit-list-layout',
            renderTo: workspace.window.$dom,
/*            west: {
                width: '40%',
                title: 'T_LIMS_LOCATION_BOARD.GRID.TITLE',
                items: [this.getGridParam()]
            },
            center: {
                items: [{
                    type: 'iframe',
                    src : '/static/basemodule/samplemanage/squareboard/index.html',
                    id : 'ksh-location-board-iframe'
                }]
            },*/
            center:{
                title: 'T_LIMS_LOCATION_BOARD.GRID.TITLE',
                items: [this.getGridParam()]
            }
        });
    },

    init: function () {
        this.create();
    }
};
